package com.mxx.common.flow;

import com.mxx.common.conv.DataCov;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author: mxx
 * @date: 2021/12/29
 * @time: 17:06
 * @Description: 描述信息
 */
public class FlowContext {

    private List<FlowEvent> callChain;

    private FlowEvent currentEvent;

    private Map<String, Object> attr;

    private boolean next = false;

    private String tradId;


    public FlowContext(FlowEvent currentEvent, Map<String, Object> attr) {
        this.callChain = new ArrayList<>();
        this.currentEvent = currentEvent;
        this.attr = attr;
    }

    public String tradId() {
        return tradId;
    }

    protected void setTradId(String tradId) {
        this.tradId = tradId;
    }

    protected void addCallChain(FlowEvent event) {
        this.callChain.add(event);
    }

    protected List<FlowEvent> callChain() {
        return this.callChain;
    }

    public void next() {
        this.next = true;
    }

    public void resetNext() {
        this.next = false;
    }

    public boolean hasNext() {
        return this.next;
    }


    public Integer getInt(String val) {
        return DataCov.toInt(attr.get(val));
    }

    public String getString(String val) {
        return DataCov.toStr(attr.get(val));
    }

    public Long getLong(String val) {
        return DataCov.toLong(attr.get(val));
    }

    public Boolean getBoolean(String val) {
        return DataCov.toBool(attr.get(val));
    }

    public Short getShort(String val) {
        return DataCov.toShort(attr.get(val));
    }

    public BigDecimal getBigDecimal(String val) {
        return DataCov.toBigDecimal(attr.get(val));
    }

    public Double getDouble(String val) {
        return DataCov.toDouble(attr.get(val));
    }

    public Float getFloat(String val) {
        return DataCov.toFloat(attr.get(val));
    }

    public FlowContext addAttr(String k, Object v) {
        this.attr.put(k, v);
        return this;
    }

    public FlowEvent currentEvent() {
        return currentEvent;
    }
}
